/**
 * Created by robot
 * DATE 2019/1/7
 * Describe
 */
'use strict';
require('./index.css')
let {MODEL} = require('g_util/app_model.js')
let index_invoice = {
  nav: {
    // 0表示底部  1表示顶部
    model: MODEL
  },
  init: function () {
    this.bindEvent()
    this.showTabByModel()
  },
  bindEvent: function () {
    var that = this
    // 绑定点击事件
    $('.invoice_top_tab .tab_item').click(function (event) {
      $(this).siblings().removeClass('actived')
      $(this).addClass('actived')
      that.loadPage($(this).attr('data-page'))
    })
  },
  showTabByModel: function () {
    var hide_css = {display: 'none'}
    var show_css = {display: 'flex'}
    // 根据设定的模式进行tab的展示
    if (!this.nav.model) {
      $('.invoice_top_tab').css(hide_css)
      $('.invoice_footer_tab').css(show_css)
      $('.invoice_footer_tab .tab_item').eq(0).click()
    } else {
      $('.invoice_footer_tab').css(hide_css)
      $('.invoice_top_tab').css(show_css)
      $('.invoice_top_tab .tab_item').eq(0).click()
    }
  },
  loadPage: function (url) {
    $('.invoice_content').load(url, function (res, status, xhr) {
      $('.invoice_header_title').text(res.substring(res.indexOf('<title>') + 7, res.indexOf('</title>')))
    })
  }
}
// 初始化页面
$(function () {
  index_invoice.init()
})
